<?php
namespace Admin\Controller;

class AccountController extends GroupController {
    /**
     * 修改密码
     */
    function uppwd() {
        $p_old = I('post.old');
        $p_new = I('post.new');
        $p_ck = I('post.ck');

        if (empty($p_old) || empty($p_new) || empty($p_ck)) {
            $this->display();
            exit;
        }

        if ($p_old == $p_new) {
            $this->error('新密码和旧密码不能一致');
        }
        if ($p_new != $p_ck) {
            $this->error('新密码和确认密码不一致');
        }

        //修改
        $aid = $_SESSION['admin']['id'];
        $res = D('Admin')->uppwd($aid, $p_old, $p_new);
        if (!$res) {
            $this->error('旧密码错误');
        }

        $this->redirect('Admin/Auth/logout');
    }
}